﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web_Oto.Business;
using Web_Oto.Common;

namespace Web_Oto.UC
{
    public partial class WebUserControl1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
                GetCategories();
        }

        private void GetCategories()
        {
            var categoryBus = new CategoryBus();
            var roots = categoryBus.GetCategoryByParentId(null);
            if(roots.Any())
            {
                var sb = new StringBuilder();
                foreach (var root in roots)
                {
                    sb.AppendFormat("<div class='title'><span>{0}</span></div>", root.Name);
                    var childrent = categoryBus.GetCategoryByParentId(root.Id);
                    if(childrent.Any())
                    {
                        sb.Append("<ul>");
                        foreach (var child in childrent)
                        {
                            sb.AppendFormat("<li rel='{1}'><a href='/san-pham/{0}/{1}/1.html'>{2}</a></li>",
                                CommonHelper.NiceUrl(root.Name),CommonHelper.NiceUrl(child.Name),child.Name);
                        }
                        sb.Append("</ul>");
                    }
                }
                ltrLeftMenu.Text = sb.ToString();
            }
        }
    }
}